﻿using EagleProject.LinQDataContext;
using EagleProject.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace EagleProject.Controllers
{
    public class ConsultantController : MyController
    {
        public ActionResult Success()
        {
            if (!IsAuthenticated()) return RedirectToLogin(@"~/Consultant/Success/");
            if (!IsConsultant()) return RedirectToAccessDenied();

            return View();
        }

        //
        // GET: /Consultant/
        public ActionResult Index()
        {
            if (!IsAuthenticated()) return RedirectToLogin(@"~/Consultant/");
            if (!IsConsultant()) return RedirectToAccessDenied();

            return View();
        }


        // GET: /Consultant/CreateAgent/
        public ActionResult CreateAgent()
        {
            if (!IsAuthenticated()) return RedirectToLogin(@"~/Consultant/CreateAgent/");
            if (!IsConsultant()) return RedirectToAccessDenied();

            ViewBag.ListState = new SelectList(DatabaseController.GetStates(), "ID", "Name");
            ViewBag.ListLGAs = new SelectList(DatabaseController.GetLGAs(), "ID", "Name");

            return View();
        }

        // POST: /Consultant/CreateAgent/
        [HttpPost]
        public ActionResult CreateAgent(FormAgentModel model)
        {
            if (!IsAuthenticated()) return RedirectToLogin(@"~/Consultant/CreateAgent/");
            if (!IsConsultant()) return RedirectToAccessDenied();

            model.ConsultantID = GetUserInformation().ID;

            DatabaseController.CreateAgentCommonUser(model);

            return View("Success");
        }
    }
}
